﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NIKE_Project.DAL;

namespace NIKE_Project.BLL
{
    public class SignInServer
    {
        DBHelper db = new DBHelper();
        private RegisterServer server = new RegisterServer();
        DataSet ds;
        public DataSet SqlUseMethod(string userName)
        {
            string SqlUse = string.Format("select SalesmanID,SalesmanName,Mobile,Pwd,Gender,BaseSalary,CommissionRate,Role from Salesan where Mobile='{0}';", userName);
            //int rows = db.logons(SqlUse);
            DataSet ds = db.getDataSet(SqlUse);
            return ds;
        }

        public DataSet SqlPwdMethod(string userName, string password)
        {
            string SqlPwd = string.Format("select Mobile,Pwd from Salesan where Mobile='{0}' and Pwd='{1}';", userName, server.GenerateMD5(password));
            DataSet ds1 = db.getDataSet(SqlPwd);
            return ds1;
        }
        public DataSet Sqldv5Method()
        {
            DataSet ds;
            string Sqldv5 = string.Format("select * from Salesan;");
            ds = db.getDataSet(Sqldv5);
            return ds;
        }
        public int SqlupdateMethod(string userName, string oldpwd, string newpwd)
        {

            string Sqlupdate = string.Format(@"update Salesan set Pwd='{0}' where Mobile='{1}' and Pwd = '{2}'", server.GenerateMD5(newpwd), userName, server.GenerateMD5(oldpwd));
            int rows = db.zsg(Sqlupdate);
            if (rows > 0)
            {
                //MessageBox.Show("修改成功！");
                //this.Close();
                //DataGridView5刷新
                // ds = signInServer.Sqldv5Method();

            }
            else
            {
                // MessageBox.Show("修改失败！");
                throw new Exception();
            }
            return rows;
        }


    }
}
